<template>
  <footer class="main-footer sticky footer-type-1">
    <div class="footer-inner">
      <div class="footer-text">
        <a href="javascript:void(0)"><strong>{{copyright}}</strong></a>
        &nbsp;&nbsp;&nbsp;&nbsp;<a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">{{beian}}</a>
      </div>

      <div class="go-up">
        <a href="javascript:void(0)" rel="go-top" @click="clickGotop">
          <i><svg-icon icon-class="top" /></i>
        </a>
      </div>
    </div>
  </footer>
</template>

<script>
import { getInfo } from "@/api/index";

export default {
  name: 'Footer',
  data() {
    return {
      baseURL: process.env.NODE_ENV === 'development'?process.env.VUE_APP_BASE_API+'/':'',
      copyright: '© oxings.com',
      beian: ''
    }
  },
  methods: {
    clickGotop() {
      window.scrollTo({top:0,behavior: 'smooth'});
    }
  },
  created() {
    getInfo().then(res =>{ //设置标题、关键字、描述
      if(res.data.title){
        document.title = res.data.title;
      }

      let metaDescription = document.querySelector('meta[name="description"]'); //查找元素 description
      if (metaDescription) {
        metaDescription.setAttribute('content', res.data.description);
      } else { // description 不存在
        if(res.data.description){
          let metaDescription = document.createElement('meta');
          metaDescription.setAttribute('name', 'description');
          metaDescription.setAttribute('content', res.data.description);
          document.querySelector('title').insertAdjacentElement('afterend', metaDescription); // 在title元素后面插入新元素
        }
      }

      let metaKeywords = document.querySelector('meta[name="keywords"]'); //查找元素 keywords
      if (metaKeywords) {
        metaKeywords.setAttribute('content', res.data.keywords);
      } else { // keywords 不存在
        if(res.data.keywords){
          let metaKeywords = document.createElement('meta');
          metaKeywords.setAttribute('name', 'keywords');
          metaKeywords.setAttribute('content', res.data.keywords);
          document.querySelector('title').insertAdjacentElement('afterend', metaKeywords);
        }
      }

      if(res.data.copyright){
        this.copyright=res.data.copyright
      }

      if(res.data.beian){
        this.beian=res.data.beian
      }
    });
  }
}
</script>

<style scoped>
.footer-inner {
  display: flex;
  justify-content: center;
  position: relative;
}
.go-up {
  position: absolute;
  right: 0;
  height: 15px;
}
</style>
